<?php

namespace App\Http\Controllers\Admin;

use App\Api\Serializer\CustomSerializer;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Admin\CategoryRequest;
use App\Models\Category;
use App\Transformers\CategoryTransformer;
use Illuminate\Http\Request;

class CategoryController extends BaseController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $all = Category::all();
        return $this->response->collection($all,new CategoryTransformer(),function ($resource, $fractal) {
            $fractal->setSerializer(new CustomSerializer());
        });


    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(CategoryRequest $request)
    {
//        $cate_name = $request->input('cate_name');
        Category::create($request->all());
        return $this->response->created();


    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show(Category $category)
    {

        return $this->response->item($category,new CategoryController(),function ($resource, $fractal) {
            $fractal->setSerializer(new CustomSerializer());
        });
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Category $category)
    {

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
//    public function destroy($id)
//    {
//        //
//    }
    public function lock(Category $category)
    {


    }
}
